using System;
using System.Collections;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Serialization;

namespace WebApplication
{
	[Serializable]
	public class TokenCollection : ICollection
	{
		private ArrayList  _aTokens;

		public Token this [int index]   // indexer declaration
		{ 
			get
			{
				return (Token) _aTokens[index];
			}

			set
			{
				_aTokens[index] = value;
			}
		}

		public void CopyTo(Array a, int index)
		{
			_aTokens.CopyTo(a, index);
		}
		public object SyncRoot
		{
			get{return this;}
		}
		public bool IsSynchronized
		{
			get{return false;}
		}

		public int Count
		{
			get
			{
				return _aTokens.Count;
			}
		}

		public TokenCollection ()
		{
			_aTokens = new ArrayList ();
		}

		public void Add (System.Object Token)
		{
			_aTokens.Add (Token);
		}

		public void Add (Token Token)
		{
			_aTokens.Add (Token);
		}

		public void Remove (Token Token)
		{
			_aTokens.Remove (Token);
		}

		// IEnumerable Interface Implementation:

		public IEnumerator GetEnumerator() // non-IEnumerable version
		{
			return _aTokens.GetEnumerator ();
		}

		IEnumerator IEnumerable.GetEnumerator() // IEnumerable version
		{
			//			return (IEnumerator) new TokenEnumerator(this);
			return _aTokens.GetEnumerator ();
		}
	}

	[Serializable]
	public class Token
	{
		private		PublicCompany	_company;
		[NonSerialized] private ImageButton _button;
		private		Side			_locationInHex;			// Some hexes, such as 59 and Toronto, have separte cities.  This indicates where in the city the token is.

		public const int tokenHeight = 24;
		public const int tokenWidth = 24;

		public Side	LocationInHex
		{
			get { return _locationInHex; }
			set { _locationInHex = value; }
		}

		//[XmlIgnore]		// Should be ok, TODO test this with undo.
		public ImageButton Button
		{
			get { return _button; }
			set { _button = value; }
		}

		public PublicCompany Company
		{
			get { return _company; }
			set { _company = value; }
		}

		public Token ()
		{
			_company = null;
			_locationInHex = null;
			_button = null;
		}
	}
}
